const fs = require('fs-extra')
const path = require('path')
const ora = require('ora')
const logSymbols = require("log-symbols");
const chalk = require("chalk");
const CONST = require('../conf/const');
const { resolve } = require('path');
module.exports =async function (target, folderName) {
  const spinner = ora(`正在下载项目模板`)
  const tplAddress= path.join(__dirname,`../tpl/${folderName}`)
  target = path.join(CONST.TEMPLATE_NAME)
  spinner.start()
  return new Promise((resolve,reject) => {
    fs.copy(tplAddress, target, function (err) {
        if (err) {
            spinner.fail()
            console.log(logSymbols.fail, chalk.red("模板下载失败:("));
            reject(err)
          } else {
            spinner.succeed()
            console.log(logSymbols.success, chalk.green("模板下载完毕:)"));
            resolve(target)
          }
      });
  })

}
